﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using RMS.Controller;

namespace RMS.View
{
    public partial class AcademicDutyView : UserControl
    {
        private AcademicDutyController _controller;

        public AcademicDutyView()
        {
            InitializeComponent();
        }

        public AcademicDutyController Controller
        {
            get { return this._controller; }
            set { this._controller = value; }
        }

        public void RefreshProgramList(List<Model.AcademicProgram> listPrograms)
        {
            this.listViewPrograms.Items.Clear();
            foreach (Model.AcademicProgram program in listPrograms)
            {
                ListViewItem item = new ListViewItem();
                item.Text = program.Name;
                item.SubItems.Add(program.Id.ToString());
                item.SubItems.Add(program.Name);
                item.SubItems.Add(program.Type.ToString());
                item.SubItems.Add(program.SemesterCount.ToString());
                this.listViewPrograms.Items.Add(item);
            }
        }

        public void RefreshDisciplineList(List<Model.Discipline> listDisciplines)
        {
            this.listViewDisciplines.Items.Clear();
            foreach (Model.Discipline discipline in listDisciplines)
            {
                ListViewItem item = new ListViewItem();
                item.Text = discipline.Name;
                item.SubItems.Add(discipline.Id.ToString());
                item.SubItems.Add(discipline.Name);
                item.SubItems.Add(discipline.Description);
                item.SubItems.Add(discipline.Semester.ToString());
                this.listViewDisciplines.Items.Add(item);
            }
        }

        public void RefreshScheduleList(List<Tuple<Model.Discipline, int, int, int>> listSchedule)
        {
            this.listViewSchedule.Items.Clear();
            foreach (Tuple<Model.Discipline, int, int, int> tuple in listSchedule)
            {
                ListViewItem item = new ListViewItem();
                item.Text = tuple.Item1.Name;
                item.SubItems.Add(tuple.Item2.ToString());
                item.SubItems.Add(tuple.Item3.ToString());
                item.SubItems.Add(tuple.Item4.ToString());
                this.listViewSchedule.Items.Add(item);
            }
        }

        private void listViewPrograms_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listViewPrograms.SelectedItems.Count > 0)
                this._controller.PopulateDisciplineList(Convert.ToInt32(this.listViewPrograms.SelectedItems[0].SubItems[1].Text));
        }

        private void listViewDisciplines_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.listViewDisciplines.SelectedItems.Count > 0)
                    this._controller.PopulateScheduleList(Convert.ToInt32(this.listViewPrograms.SelectedItems[0].SubItems[1].Text), Convert.ToInt32(this.listViewDisciplines.SelectedItems[0].SubItems[1].Text));
            }
            catch { }
        }
    }
}
